package test
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	import level4.display.GameDispose;
	import level4.gc.GC;

	public class GameDisposeTest extends GameDispose
	{
		private var arr:Array=[];
		public function GameDisposeTest()
		{
		}
		
		override public function init(e:Event):void{
			var count:int = 100;
			for(var i:int=0;i<count;i++){
				var gd:GameDispose = new GameDispose();
								addChild(gd);
				arr.push(gd);
				gd.addEventListener(Event.ENTER_FRAME,loop);
				gd.graphics.beginFill(0xffffff * Math.random());
				gd.graphics.drawRect(0,0,40,30);
				gd.graphics.endFill();
				gd.x = Math.random() * 400;
				gd.y = Math.random() * 300;
			}
//			stage.addEventListener(MouseEvent.CLICK,onClick);
			var timerId:int = setTimeout(function():void{
				clean();
				clearTimeout(timerId);
			},2000);
		}
		
		private function onClick(e:MouseEvent):void{
			var timerId:int = setTimeout(function():void{
				clean();
				clearTimeout(timerId);
			},1);
		}
		
		private function clean():void{
			for each(var gd:GameDispose in arr){
				gd.dispose();
			}
			arr.length=0;
			GC.LC();
		}
		
		private function loop(e:Event):void{
			trace("a");
		}
	}
}